﻿
using Furion;
using System;

namespace PIP.Common
{
    public class Helper
    {
        public static string GetEnvironment()
        {
            var yygh = App.Configuration["ConnectionStrings:SqlServerYyghDbConnectionString"];
            //var mysqlConn = App.Configuration["ConnectionStrings:GardenerMysqlDbConnectionString"];
            var hisConn = App.Configuration["ConnectionStrings:SqlServerHISDbConnectionString"];
            //var pubConn = App.Configuration["ConnectionStrings:GardenerSqlServerDbConnectionString"];
            return
              $"环境类型: {App.Configuration["ConnectionStrings:ConnType"]}|" +
              $"预约挂号:{get连接串IP及端口(yygh)},{get连接串dbName(yygh)}| " +
              //$"Mysql数据库:{get连接串IP及端口(mysqlConn)},{get连接串dbName(mysqlConn)}| " +
              $"HIS数据库:{get连接串IP及端口(hisConn)},{get连接串dbName(hisConn)}| " +
              //$"公用数据库: {get连接串IP及端口(pubConn)},{get连接串dbName(pubConn)}|" +
              $"当前时间{DateTime.UtcNow}";
        }

        public static string get连接串dbName(string strSqlConn)
        {
            if (string.IsNullOrWhiteSpace(strSqlConn))
            {
                return "未设置";
            }
            string sRe = "";
            try
            {
                string[] arr = strSqlConn.Split(';');
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i].ToLower().IndexOf("database=") >= 0 || arr[i].IndexOf("catalog=") >= 0)
                    {
                        sRe = arr[i].Split('=')[1];
                    }
                }
                return sRe;
            }
            catch (Exception ex)
            {
                return "";
            }
        }
        public static string get连接串IP及端口(string strSqlConn)
        {
            if (string.IsNullOrWhiteSpace(strSqlConn))
            {
                return "未设置";
            }
            string sRe = "";
            try
            {
                string[] arr = strSqlConn.Split(';');
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i].ToLower().IndexOf("source=") >= 0 || arr[i].ToLower().IndexOf("server=") >= 0)
                    {
                        sRe = arr[i].Split('=')[1];
                    }
                }
                return sRe;
            }
            catch (Exception ex)
            {
                return "";
            }
        }
    }
}
